/**
 * 
 */
package com.module.bp.player;

import com.dalonedrau.jogl.engine.Animation;
import com.dalonedrau.jogl.engine.GameApplet;
import com.dalonedrau.jogl.engine.Interactive;
import com.dalonedrau.jogl.opengl.animation.AnimationSequenceObject;
import com.dalonedrau.jogl.opengl.animation.AnimationSequenceObjectFactory;
import com.dalonedrau.jogl.opengl.sprite.BasicSpriteObject;
import com.dalonedrau.jogl.opengl.sprite.SpriteBase;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObject;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObjectFactory;
import com.dalonedrau.vectors.Vector3;
import com.module.bp.script.BPScriptable;
import com.rpg.base.interactive.flyweight.InteractiveObject;

/**
 * @author Donald
 */
public final class BPPartyWMSprite extends InteractiveObject implements
		BPScriptable {
	/**
	 * Creates a new instance of {@link BPPartyWMSprite}.
	 */
	public BPPartyWMSprite() {
		super(Interactive.getInstance().getNextId());
		try {
			Interactive.getInstance().addIO(this);
			SpriteBase sb = new BasicSpriteObject();
			SpriteImageObject img =
					SpriteImageObjectFactory.getInstance().getImageByName(
							"party_walk_d_0");
			sb.setImageRefId(img.getRefId());
			sb.setWidth(img.getWidth());
			sb.setHeight(img.getHeight());
			sb.setPosition(new Vector3(-200, -200, 0));
			setSprite(sb);
			initializeAnimations();
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	private void initializeAnimations() {
		try {
			// initialize walk animations
			AnimationSequenceObject anim = 
				AnimationSequenceObjectFactory.getInstance().getSequenceByName(
						"party_walk_d");
			anim.setEndKeyFrame(1);
			anim = 
				AnimationSequenceObjectFactory.getInstance().getSequenceByName(
						"party_walk_l");
			anim.setEndKeyFrame(1);
			anim = 
				AnimationSequenceObjectFactory.getInstance().getSequenceByName(
						"party_walk_r");
			anim.setEndKeyFrame(1);
			anim = 
				AnimationSequenceObjectFactory.getInstance().getSequenceByName(
						"party_walk_u");
			anim.setEndKeyFrame(1);
			addAnimation("party_walk_d",
					AnimationSequenceObjectFactory.getInstance()
							.getSequenceRefId("party_walk_d"));
			addAnimation("party_walk_l",
					AnimationSequenceObjectFactory.getInstance()
							.getSequenceRefId("party_walk_l"));
			addAnimation("party_walk_r",
					AnimationSequenceObjectFactory.getInstance()
							.getSequenceRefId("party_walk_r"));
			addAnimation("party_walk_u",
					AnimationSequenceObjectFactory.getInstance()
							.getSequenceRefId("party_walk_u"));
			Animation.getInstance().playAnimation(this,
					getAnimation("party_walk_d"));
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onAddToParty() { }

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onInit() {
		// TODO Auto-generated method stub

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void onOverworldMapWalk(final int direction, final long flags) {
		try {
		switch (direction) {
		case BPConsts.DIR_NORTH:
			Animation.getInstance().playAnimation(this,
					getAnimation("party_walk_d"), flags);
			break;
		case BPConsts.DIR_EAST:
			Animation.getInstance().playAnimation(this,
					getAnimation("party_walk_r"), flags);
			break;
		case BPConsts.DIR_SOUTH:
			Animation.getInstance().playAnimation(this,
					getAnimation("party_walk_d"), flags);
			break;
		default:
			Animation.getInstance().playAnimation(this,
					getAnimation("party_walk_l"), flags);
			break;
		}
	} catch (Exception ex) {
		JOGLErrorHandler.getInstance().fatalError(ex);
	}
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public SpriteBase onSmallPortrait() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
